BIN	 = video
CC	 = ../../prebuilts/toolschain/usr/bin/arm-linux-gcc
CPP	 = ../../prebuilts/toolschain/usr/bin/arm-linux-g++

INCS	 = -I./../../out/system/include/ -I./ -Iav_wrapper/ -I./watermark/ -I./power/ -I../recovery/src/init_hook_dir/ -I./flyctl_app/ -I./sfserver/include/ -I./utils/flow/include/ -I./utils/track/include

LIBS	 = -L./../../out/system/lib -L./utils/flow/lib -L./utils/track/lib \
		   -lalgtrack -lljflow -lcam_hal \
           -lm -lpthread -ldl \
           -lpng -lion -lvpu -lmpp -lrkipc \
           -lswresample      \
           -lavformat -lavcodec -lavutil -lfdk-aac -lz \
           -lsalsa -lfsmanage -ldpp -lrk_backtrace -liep \
           -lrkfb -lrkrga

LIBS += -L./sfserver/lib -lsfserver

ifeq ($(RK_PROTOCOL_GB28181),YES)
	LIBS += \
				-lrk_gb28181 -leXosip2 -losip2 -losipparser2 -lmxml
endif

ifeq ($(RK_FWK_MSG),YES)
	LIBS += \
				-lfwk_controller -lfwk_glue -lfwk_msg -ljsoncpp
endif

ifeq ($(RK_PROTOCOL_IOTC),YES)
	LIBS += \
				-lrk_iotc -lP2PTunnelAPIs -lRDTAPIs -lAVAPIs -lIOTCAPIs
endif

TMP_CSRCS = $(wildcard *.c av_wrapper/decoder_demuxing/*.c customer_interface/*.c power/*.c ueventmonitor/*.c collision/*.c parking_monitor/*.c watermark/*.c storage/*.c flyctl_app/*.c)

ETCPATH  = ../../out/system/etc
RESPATH  = ../../out/system/share/minigui/res/images

define all-cpp-files-under
$(shell find $(1) -name "*."$(2) -and -not -name ".*" )
endef

define all-subdir-cpp-files  
$(call all-cpp-files-under,.,"cpp")
endef

CPPSRCS	 = $(call all-subdir-cpp-files)

CSRCS = $(filter-out customer_interface/test_interface.c camera_ui.c, $(TMP_CSRCS))

COBJS	:= $(CSRCS:.c=.o)
CPPOBJS	:= $(CPPSRCS:.cpp=.o)

USERFLAGS :=
#USERFLAGS += -DENABLE_MD_IN_MENU -DCACHE_ENCODEDATA_IN_MEM

DEBUGFLAGS = -fexceptions -finstrument-functions -funwind-tables -g -rdynamic -O0 -DDEBUG
#DEBUGFLAGS += -DSTRESS_TEST
#DEBUGFLAGS += -DMUL_ENCODERS_DEBUG
OPTIMIZEFLAGS = -O3 -Wl,-gc-sections
CFLAGS	 = -Wno-multichar
CPPFLAGS = -DSUPPORT_ION -std=c++11 -DLINUX  -DENABLE_ASSERT -Wno-multichar -DResolution

CFLAGS += $(DEBUGFLAGS)
CPPFLAGS += $(DEBUGFLAGS)
#CFLAGS += $(OPTIMIZEFLAGS)
#CPPFLAGS += $(OPTIMIZEFLAGS)
CFLAGS += $(USERFLAGS)
CPPFLAGS += $(USERFLAGS)

CFLAGS += -DHAVE_GUI=0 -DUSE_WATERMARK -DHAVE_DISPLAY=0
CPPFLAGS += -DHAVE_GUI=0 -DUSE_WATERMARK -DHAVE_DISPLAY=0

CPPFLAGS += -D USE_RK_V4L2_HEAD_FILES
CPPFLAGS += -DDISABLE_FF_MPP

ifeq ($(RK_PROTOCOL_GB28181),YES)
	CPPFLAGS += -DPROTOCOL_GB28181
	CFLAGS += -DPROTOCOL_GB28181
endif

ifeq ($(RK_FWK_MSG),YES)
	CPPFLAGS += -DMSG_FWK
	CFLAGS += -DMSG_FWK
endif

ifeq ($(RK_PROTOCOL_IOTC),YES)
	CPPFLAGS += -DPROTOCOL_IOTC
	CFLAGS += -DPROTOCOL_IOTC
endif

#copy the res to device
$(shell cp -r res/watermark/* $(RESPATH) )

all : $(BIN)

$(COBJS) : %.o : %.c
	@$(CC) -c $< -o $@ $(INCS) $(CFLAGS) $(LIBS)
$(CPPOBJS) : %.o : %.cpp
	@$(CPP) -c $< -o $@ $(INCS) $(CPPFLAGS) $(LIBS)

$(BIN) : $(COBJS) $(CPPOBJS)
	@$(CPP) -o $(BIN) $(COBJS) $(CPPOBJS) $(LIBS)
	@-rm $(COBJS) $(CPPOBJS)
	@echo "video build success!"
			
clean:
	@rm -f $(BIN) $(COBJS) $(CPPOBJS)
	@echo "video clean success!"
